package com.eastfair.venueservice.config.task;

import com.eastfair.core.context.ContextUtil;
import com.eastfair.venueservice.enumeration.ServiceProviderTypeEnum;
import com.eastfair.venueservice.service.ServiceProviderService;
import core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 服务商任务.
 *
 * @author dqq
 * @date 2023 /2/9
 */
@Slf4j
@Component
public class ServiceProviderTask {

    private static final long FIX_DELAY = 1800000L;

    @Value("${com.eastfair.projectId}")
    private Long projectId;

    @Resource
    private ServiceProviderService serviceProviderService;

    /**
     * 更新主场服务商为失效任务执行.
     */
//    @Scheduled(fixedDelay = FIX_DELAY)
    @XxlJob("updateHomeServiceProviderDisable")
    public void updateHomeServiceProviderDisable() {
        log.info("updateHomeServiceProviderDisable - 更新主场服务商为失效任务执行");
        ContextUtil.setProjectId(projectId);
        serviceProviderService.updateServiceProviderDisableByType(ServiceProviderTypeEnum.HOME_SERVICE_PROVIDER.getCode());
    }

    /**
     * 更新搭建服务商为失效任务执行.
     */
//    @Scheduled(fixedDelay = FIX_DELAY)
    @XxlJob("updateBuilderServiceProviderDisable")
    public void updateBuilderServiceProviderDisable() {
        log.info("updateBuilderServiceProviderDisable - 更新搭建服务商为失效任务执行");
        ContextUtil.setProjectId(projectId);
        serviceProviderService.updateServiceProviderDisableByType(ServiceProviderTypeEnum.BUILD_SERVICE_PROVIDER.getCode());
    }

    /**
     * 更新主运服务商为失效任务执行.
     */
//    @Scheduled(fixedDelay = FIX_DELAY)
    @XxlJob("updateMainTransportServiceProviderDisable")
    public void updateMainTransportServiceProviderDisable() {
        log.info("updateMainTransportServiceProviderDisable - 更新主运服务商为失效任务执行");
        ContextUtil.setProjectId(projectId);
        serviceProviderService.updateServiceProviderDisableByType(ServiceProviderTypeEnum.MAIN_TRANSPORT_SERVICE_PROVIDER.getCode());
    }

    /**
     * 更新配套服务商为失效任务执行.
     */
//    @Scheduled(fixedDelay = FIX_DELAY)
    @XxlJob("updateMatchServiceProviderDisable")
    public void updateMatchServiceProviderDisable() {
        log.info("updateMatchServiceProviderDisable - 更新配套服务商为失效任务执行");
        ContextUtil.setProjectId(projectId);
        serviceProviderService.updateServiceProviderDisableByType(ServiceProviderTypeEnum.MATCHING_SERVICE_PROVIDER.getCode());
    }
}